// client.cpp
#define _WIN32_DCOM
#include <iostream.h>
#include <stdio.h>
#include "Component\component.h"

void main()
{
	cout << "Client: Calling CoInitialize()" << endl;
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
		
	ISum* pSum = 0;

//	cout << "Client: Calling CoCreateInstance() " << endl;
//	CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);

	HRESULT hr = 0;
	

	COSERVERINFO csi = { 0, 0, 0, 0 };
//	csi.pwszName = L"RemoteMachineName";

	BIND_OPTS2 bopts;
	bopts.dwClassContext = CLSCTX_LOCAL_SERVER;
	bopts.cbStruct = sizeof(BIND_OPTS2);
	bopts.pServerInfo = &csi;

//	hr = CoGetObject(L"new:Component.InsideCOM", &bopts, IID_ISum, (void**)&pSum);
	hr = CoGetObject(L"new:10000002-0000-0000-0000-000000000001", &bopts, IID_ISum, (void**)&pSum);
	if(FAILED(hr))
		printf("hr = %0x\n", hr);

	cout << "Client: pSum = " << pSum << endl;

	int sum;
	hr = pSum->Sum(4, 9, &sum);
	if(SUCCEEDED(hr))
		cout << "Client: Calling Sum() return value is " << sum << endl;

	cout << "Client: Calling Release() for pSum" << endl;
	hr = pSum->Release();

	cout << "Client: Calling CoUninitialize()" << endl;
	CoUninitialize();
}